#!/usr/bin/env python
import simcat.client as client

lca = client.get('entity', 'lca')
cool = client.get('datacollection', 'cool')
enzo = client.get('protocol', 'enzo')

clrc00 = client.models.Experiment()
clrc00.protocol = enzo
clrc00.collection = cool
clrc00.name = "CLRC00"
clrc00.short_name = "CLRC00"
clrc00.publisherDID = "lca/sca/cool/clrc00"
clrc00.save()

contact = client.models.Contact(resource=clrc00, entity=lca, role="publisher")
contact.save()
contact = client.models.Contact(resource=clrc00, entity=lca, role="owner")
contact.save()

param_file = open('clrc00_0000')
lines = param_file.readlines()
param_file.close()
for line in lines:
    try:
        param, val = line.split('=')
        param = param.strip()
        val = val.strip()
        input_param = enzo.inputparameter_set.get(name=param)
        setting = client.models.ParameterSetting()
        setting.experiment = clrc00
        setting.parameter = input_param
        setting.parameter_name = param
        setting.value = val
        setting.save()
    except:
        # print "Line not used: %s" % line
        pass

# json = clrc00.to_json(indent=2)
# print json

# clrc002 = client.models.Experiment()
#clrc002.from_json(json)
# print clrc002.to_json(indent=2)

client.add(clrc00)
